package com.liuke.study.thread;

import java.util.ArrayList;
import java.util.List;

/**
 * TODO
 *
 * @author wangjwy
 * @date 2019/10/24 14:17
 * @since 1.0.0
 */
public class Test9 {

	public static void main(String[] args) {
		List<String> availableTargetNames = new ArrayList<String>();
		for (int i = 0; i < 100; i++) {
			availableTargetNames.add("tb_account1" + i);
		}

		String shortName = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
		for (String table : availableTargetNames) {
			if (shortName.length() >= table.length()) {
				shortName = table;
			}
		}
		boolean flag = false;
		while (true) {
			if (shortName == "") {
				break;
			}
			for (String targetName : availableTargetNames) {
				if (!targetName.startsWith(shortName)) {
					shortName = shortName.substring(0, shortName.length() - 1);
					flag = true;
					break;
				}
			}
			if (flag) {
				flag = false;
				continue;
			} else {
				break;
			}
		}
		System.out.println(shortName);
	}

}
